import 'package:flutter_bloc/flutter_bloc.dart';

// //计数器 Bloc
// class CounterBloc extends Bloc<CounterEvent, int> {
//   CounterBloc() : super(0) {
//     print("CounterEvent=======$CounterEvent");
//     on<CounterIncrementPressed>((event, emit) => emit(state + 1));
//     on<CounterDecrementPressed>((event, emit) => emit(state - 1));
//   }
// }
//计数器 Bloc---事件类型改成int类型
class CounterBloc extends Bloc<int, int> {
  CounterBloc() : super(0) {
    on<int>((event, emit) {
      if (event == 1) {
        emit(state +1);
      }else {
        emit(state -1);
      }
    });
  }
}

// abstract class CounterEvent {}
//
// class CounterIncrementPressed extends CounterEvent {}
//
// /// Notifies bloc to decrement state.
// class CounterDecrementPressed extends CounterEvent {}

// 用户信息 Bloc
class UserInfoBloc extends Bloc<UserInfoEvent, UserInfo1> {
  UserInfoBloc() : super(UserInfo1("", 0, ""));

  @override
  Stream<UserInfo1> mapEventToState(UserInfoEvent event) async* {
    if (event is UpdateUserInfoEvent) {
      yield event.userInfo;
    }
  }
}

// 用户信息事件类
class UserInfoEvent {}

class UpdateUserInfoEvent extends UserInfoEvent {
  final UserInfo1 userInfo;

  UpdateUserInfoEvent(this.userInfo);
}

// 用户信息类
class UserInfo1 {
  final String name;
  final int age;
  final String id;

  UserInfo1(this.name, this.age, this.id);
}
